package com.liuxu.autorun;

import android.os.Build;


import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

public class ChangeInfo {
    RandomHelper Helper=new RandomHelper();

    public ChangeInfo(XC_LoadPackage.LoadPackageParam sharePkgParam){
        BuildProp(sharePkgParam);
        Telephony(sharePkgParam);
        XposedHookHelper.getInstances(sharePkgParam).Wifi.Info.getMacAddress(Helper.GetWifiMac());
        XposedHookHelper.getInstances(sharePkgParam).Wifi.Info.getSSID(Helper.GetWifiSSID());
        XposedHookHelper.getInstances(sharePkgParam).Telephony.getDeviceId(Helper.GetDeviceId());
    }

    public void BuildProp(XC_LoadPackage.LoadPackageParam loadPkgParam) {
        try {
            XposedHelpers.findField(Build.class, "BRAND").set(null, Helper.GetBRAND());
            XposedHelpers.findField(Build.class, "MODEL").set(null, Helper.GetModel());
            XposedHelpers.findField(Build.class, "PRODUCT").set(null, Helper.GetModel());
            XposedHelpers.findField(Build.class, "SERIAL").set(null, Helper.GetBuildSerial());

        }catch (Exception e) {
            XposedBridge.log(" BuilProp 错误: " + e.getMessage());
        }
    }
    public void Telephony(XC_LoadPackage.LoadPackageParam loadPkgParam) {

        String TelePhone = "android.telephony.TelephonyManager";
        HookTelephony(TelePhone, loadPkgParam, "getDeviceSoftwareVersion", Helper.GetDeviceVersion());// 返系统版本
        HookTelephony(TelePhone, loadPkgParam, "getSubscriberId",Helper.GetSimId());
        HookTelephony(TelePhone, loadPkgParam, "getLine1Number", Helper.GetTelNumber());
    }
    private void HookTelephony(String hookClass, XC_LoadPackage.LoadPackageParam loadPkgParam,
                               String funcName, final String value) {
        try {
            XposedHelpers.findAndHookMethod(hookClass,
                    loadPkgParam.classLoader, funcName, new XC_MethodHook() {

                        @Override
                        protected void afterHookedMethod(MethodHookParam param)
                                throws Throwable {
                            // TODO Auto-generated method stub
                            super.afterHookedMethod(param);
                            param.setResult(value);
                        }

                    });

        } catch (Exception e) {

        }
    }

}